package cn.maihe.elg.operation.repository.entity;

import cn.maihe.elg.operation.repository.entity.UserVo;
import cn.maihe.framework.starter.base.sql.BaseEntity;
import cn.maihe.framework.starter.base.sql.MapperInterface;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.baomidou.mybatisplus.enums.IdType;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 用户表
 */
@TableName("t_user")
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
@MapperInterface("cn.maihe.elg.operation.repository.mapper.UserMapper")
public class UserDO extends BaseEntity {
    @TableId(type = IdType.ID_WORKER)
    private Long id;

    /**
     * 证件号码
     */
    @TableField(value = "cert_no")
    private String certNo;

    /**
     * 电子邮箱
     */
    @TableField(value = "email")
    private String email;

    /**
     * 手机号码
     */
    @TableField(value = "mobile_no")
    private String mobileNo;

    /**
     * 用户姓名
     */
    @TableField(value = "name")
    private String name;

    /**
     * 登录密码
     */
    @TableField(value = "password")
    private String password;

    /**
     * 职务
     */
    @TableField(value = "post")
    private String post;

    /**
     * 性别
     */
    @TableField(value = "sex")
    private String sex;

    @TableField(value = "status")
    private String status;

    /**
     * 登录账号
     */
    @TableField(value = "username")
    private String username;

    /**
     * 所属部门编号
     */
    @TableField(value = "org_id")
    private Long orgId;

    /**
     * um登录
     */
    @TableField(value = "um_login")
    private String umLogin;

    /**
     * 登录失败次数
     */
    @TableField(value = "login_fail_times")
    private Integer loginFailTimes;

    /**
     * 上次被锁时间
     */
    @TableField(value = "last_locked_time")
    private Date lastLockedTime;

    /**
     * 创建时间
     */
    @TableField(value = "gmt_create", fill = FieldFill.INSERT)
    private Date gmtCreate;

    /**
     * 更新时间
     */
    @TableField(value = "gmt_modified", fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;

    /**
     * 创建用户
     */
    @TableField(value = "user_create", fill = FieldFill.INSERT)
    private String userCreate;

    /**
     * 更新用户
     */
    @TableField(value = "user_modified", fill = FieldFill.INSERT_UPDATE)
    private String userModified;

    /**
     * 机构代码
     */
    @TableField(value = "org_code")
    private String orgCode;

    /**
     * 0运营 1机构 2子账户
     */
    @TableField(value = "type")
    private Integer type;

    /**
     * 登录时间
     */
    @TableField(value = "last_login_time")
    private Date lastLoginTime;

    /**
     * 登录次数
     */
    @TableField(value = "login_count")
    private Integer loginCount;

    @TableField(value = "pwd_expired_time")
    private Date pwdExpiredTime;

    /**
     * 业务平台用户id 对应user信息中的userid
     */
    @TableField(value = "follow_id")
    private String followId;

    public UserVo buildVo() {
        return new UserVo(id, certNo, email, mobileNo, name, password, post, sex, status, username, orgId, umLogin, loginFailTimes, lastLockedTime, gmtCreate, gmtModified, userCreate, userModified, orgCode, type, lastLoginTime, loginCount, pwdExpiredTime, followId);
    }

    public static UserDO of(UserVo vo) {
        return new UserDO(vo.getId(), vo.getCertNo(), vo.getEmail(), vo.getMobileNo(), vo.getName(), vo.getPassword(), vo.getPost(), vo.getSex(), vo.getStatus(), vo.getUsername(), vo.getOrgId(), vo.getUmLogin(), vo.getLoginFailTimes(), vo.getLastLockedTime(), vo.getGmtCreate(), vo.getGmtModified(), vo.getUserCreate(), vo.getUserModified(), vo.getOrgCode(), vo.getType(), vo.getLastLoginTime(), vo.getLoginCount(), vo.getPwdExpiredTime(), vo.getFollowId());
    }
}
